package com.com.java8.streams;

import com.com.java8.data.Track;
import com.com.util.JunitTemplate;
import sun.rmi.runtime.Log;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by pankaj on 4/16/15.
 */
public class FilterCount {
    static Logger logger = Logger.getLogger(FilterCount.class.getName());

    public static void main(String[] args) {

        List<String> allArtists = Arrays.asList("S", "W", "S");
        long count = allArtists.stream()
                .filter(artist -> artist.startsWith("S"))
                .count();
        System.out.print(count);


        List<String> collected = Stream.of("a", "b", "c")
                .collect(Collectors.toList());

        System.out.print(collected);

        List<String> collectedUpper = Stream.of("a", "b", "hello")
                .map(string -> string.toUpperCase())
                .collect(Collectors.toList());
        System.out.print(collectedUpper);


        List<String> collected2 = Stream.of("a2", "B2", "c1")
                .filter(string -> string.contains("2"))
                .collect(Collectors.toList());
        System.out.print(collected2);

        List<Integer> together = Stream.of(Arrays.asList(1, 2), Arrays.asList(3, 4))
                .flatMap(numbers -> numbers.stream())
                .collect(Collectors.toList());
        System.out.print(together);

        List<Track> tracks = Arrays.asList(new Track("Bakai", 524),
                new Track("Violets for Your Furs", 378),
                new Track("Time Was", 451));

        Track shortestTrack = tracks.stream()
                .min(Comparator.comparing(track -> track.getLength()))
                .get();
        System.out.print(" Shortest Track: " + shortestTrack.getLength());

        getMessage("1" + getMessage2("2"));

        Predicate<Integer> atLeast5 = x -> x >5;
        if(atLeast5.test(7))
        {
            System.out.print("It is greater than 5" + atLeast5.test(7) );
        }
        else
        {
            System.out.print("It is less than 5" + atLeast5.test(5) );
        }








    }

    private static String getMessage(String anotherMessage)
    {
        logger.info("getMessage()  Called!");
        return "getMessage()  Called!";
    }

    private static String getMessage2(String anotherMessage)
    {
        logger.info("getMessage2()  Called!");
        return "getMessage2()  Called!";
    }
}
